﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Base;
using DHQGHN.DAL.Models;

namespace DHQGHN.DAL.DAO
{
    public class ServiceUsersDAO : SqlDAO
    {
        private const string PROC_CHECK_LOGIN = "spCheckLoginService";
        private const string PROC_GET_LIST_METHOD = "spGetListServiceMethodByUserName";
        private const string PARAM_USER_NAME = "@UserName";
        private const string PARAM_PASSWORD = "@Password";

        public ServiceUsersDAO(string connectionString) :
            base(connectionString) { }

        public bool CheckLogin(string userName, string password)
        {
            try
            {
                SqlCommand cmd = this.GetSprocCommand(PROC_CHECK_LOGIN);
                cmd.Parameters.Add(CreateParameter(PARAM_USER_NAME, userName));
                cmd.Parameters.Add(CreateParameter(PARAM_PASSWORD, password));
                object rely = ExecuteScalar(cmd);
                int result = rely == DBNull.Value ? 0 : (int)rely;
                return result > 0 ? true : false;
            }
            catch
            {
                throw;
            }
        }

        public List<ServiceMethodModel> GetServiceMethodByUserName(string userName, Dictionary<string, string> mapDictionary)
        {
            try
            {
                SqlCommand cmd = this.GetSprocCommand(PROC_GET_LIST_METHOD);
                cmd.Parameters.Add(CreateParameter(PARAM_USER_NAME, userName));

                List<ServiceMethodModel> result = GetList<ServiceMethodModel>(cmd, mapDictionary);

                return result;
            }
            catch
            {
                throw;
            }
        }
    }
}
